package com.nf.dao.impl;

import com.nf.dao.TicketVoDao;
import com.nf.util.DBUtil;
import com.nf.vo.TicketVo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TicketVoDaoImpl implements TicketVoDao {
    @Override
    public TicketVo selectTicket(int showId) {
        TicketVo tik=null;

        Connection conn= DBUtil.getConnection();
        String sql="select s.show_id,f.film_id,h.hall_id,f.film_name,f.film_type,f.film_long,f.film_language,f.film_picture,h.hall_name,h.hall_type,s.show_Date,s.start_time,s.price from showInfo s,filmInfo f,hallInfo h where s.film_id=f.film_id and s.hall_id=h.hall_id and s.show_id=?";
        PreparedStatement pstmt=null;
        ResultSet rst=null;
        try {
            pstmt=conn.prepareStatement(sql);
            pstmt.setInt(1,showId);
            rst= pstmt.executeQuery();
            if(rst.next()){
                int showid=rst.getInt(1);
                int filmId=rst.getInt(2);
                int hallId=rst.getInt(3);
                String filmName=rst.getString(4);
                String filmType=rst.getString(5);
                String filmLong=rst.getString(6);
                String filmLanguage=rst.getString(7);
                String filmPicture=rst.getString(8);
                String hallName=rst.getString(9);
                String hallType=rst.getString(10);
                String showDate=rst.getString(11);
                String startTime=rst.getString(12);
                Float price= rst.getFloat(13);

                tik=new TicketVo(showid,filmId,hallId,filmName,filmType,filmLong,filmLanguage,filmPicture,hallName,hallType,showDate,startTime,price);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DBUtil.close(rst,pstmt,conn);
        }
        return tik;
    }
}
